<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="日期">
        <el-date-picker v-model="form.date" type="date" placeholder="选择日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="员工">
        <el-select v-model="selectedEmployee" placeholder="请选择员工">
          <el-option
            v-for="employee in employees"
            :key="employee"
            :label="employee"
            :value="employee"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="班次">
        <el-select v-model="form.shifts[selectedEmployee]" placeholder="请选择班次">
          <el-option label="休息" value="Rest"></el-option>
          <el-option label="早班" value="Morning"></el-option>
          <el-option label="中班" value="Afternoon"></el-option>
          <el-option label="晚班" value="Evening"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { ElForm, ElFormItem, ElSelect, ElOption, ElDatePicker, ElButton } from 'element-ui';

export default {
  name: 'AddDutySchedule',
  components: {
    ElForm,
    ElFormItem,
    ElSelect,
    ElOption,
    ElDatePicker,
    ElButton
  },
  props: {
    employees: {
      type: Array,
      required: true
    },
    currentDate: {
      type: Date,
      default: () => new Date()
    }
  },
  data() {
    return {
      form: {
        date: this.currentDate,
        shifts: {}
      },
      selectedEmployee: ''
    };
  },
  methods: {
    submitForm() {
      if (this.selectedEmployee && this.form.shifts[this.selectedEmployee]) {
        this.$emit('addDuty', this.form);
      }
    },
    resetForm() {
      this.form.date = this.currentDate;
      this.form.shifts = {};
      this.selectedEmployee = '';
    }
  }
};
</script>

<style scoped>
.el-form {
  width: 400px;
  margin: 0 auto;
}
</style>